package com.example.demo;

import java.net.URL;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;

@Component
public class Consumer {

	/*public void <T> Map<String, Class<?>> getBeanClasses(String packageName,Class<T> tclass){
      
            if(clazz.isAnnotationPresent(tclass)){
                T t = tclass.newInstance();
                
            }
       
        return annotationClasses;
    }*/

	public <T> T getService(Class<T> tclass) {
		// 当前应用配置
		ApplicationConfig application = new ApplicationConfig();
		application.setName("sortServiceUser");

		// 连接注册中心配置
		RegistryConfig registry = new RegistryConfig();
		registry.setAddress("zookeeper://192.168.80.71:2181");

		// 注意：ReferenceConfig为重对象，内部封装了与注册中心的连接，以及与服务提供方的连接

		// 引用远程服务
		ReferenceConfig<T> reference = new ReferenceConfig<T>();
		reference.setApplication(application);
		reference.setRegistry(registry);
		reference.setInterface(tclass);
		reference.setVersion("1.0.0");

		T t = reference.get();
		return t;
	}

}
